import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import https from 'https';
import fs from 'fs';

// ES模块中获取__dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// 创建Express应用
const app = express();
const port = 3000;

// 提供静态文件
app.use(express.static(path.join(__dirname, '../public')));

// HTTPS配置
const options = {
  key: fs.readFileSync(path.join(__dirname, '../ssl/key.pem')),
  cert: fs.readFileSync(path.join(__dirname, '../ssl/cert.pem'))
};

// 启动HTTPS服务器
https.createServer(options, app).listen(port, () => {
  console.log(`服务器运行在 https://localhost:${port}`);
});